//index.js
//获取应用实例
var serveUrl = require('../../../utils/util.js').serveUrl 
var app = getApp()
var url = "";
var page = 0;
var page_size = 10;
var sort = "last";
var is_easy = 0;
var lange_id = 0;
var pos_id = 0;
var unlearn = 0;
var zhaopin = []


// 请求数据
var loadMore = function (that) {
  wx.showToast({
    title: '加载中...',
    icon: 'loading',
    duration: 3000
  });
  page++;
  that.setData({
    hidden: false
  });
  wx.request({
    url: serveUrl + "get_recruit_data",
    method: "POST",    
    data: {
      page: page
    },
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    success: function (res) {
      wx.hideToast();
     
      // console.info(that.data.list);
      console.log("笑啦笑啦");
      if (res.data.data == "") {

      }else{
        zhaopin = [];
      }
      for (var i = 0; i < res.data.data.length; i++) {
        if (res.data.data[i].status == 1) {
          zhaopin.push(res.data.data[i])

        }
      }
 
      console.log("oooo")
      console.log(zhaopin)
      that.setData({
        listData: zhaopin
      });
      // var list = that.data.list;
      // for (var i = 0; i < res.data.list.length; i++) {
      //   list.push(res.data.list[i]);
      // }
      // that.setData({
      //   list: list
      // });
      // page++;
      // that.setData({
      //   hidden: true
      // });
    }
  });
}
Page({
  data: {
    toView: "",
    motto: 'MiHome_Store',
    userInfo: {},
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 100,
    scrollTop: 0,
    scrollHeight: 0,
    listData:[],
  },
  scroll: function (e) {
    this.setData({
      scrollTop: e.detail.scrollTop
    });
  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  tap: function () {
    this.setData({
      toView: "top"
    })
  },
  onLoad: function () {
    var that=this;
    // 加载轮播图信息
    that.lunboImg()
    // 加载招聘信息
    that.zhaoPinList()
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
    loadMore(that);
  },
  // 轮播图点击
  lunboTap(e){
    var that=this;
    console.log(JSON.parse(e.currentTarget.id))
    var others = JSON.parse(e.currentTarget.id);
    that.addtap(others.lunbo_id);
    // 调详情
    that.goDetail(others.recruit_id.recruit_id)
  },
  // 招聘信息点击
  goDetail(recruitId){
    var that =this;
    
    wx.navigateTo({
      url: "../detailInfo/detailInfo?recruitId=" + recruitId,
      success: function (res) {
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  // 招聘列表
  zhaoPinList(){
    var that=this;
    console.log(serveUrl)
      wx.request({
        url: serveUrl+"get_recruit_data",
        method: "POST",
        header: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
        data:{
          page: page
        },
        success: function(res) {
          console.log("pppppppp")
          console.log(res);
          for(var i=0;i<res.data.data.length;i++){
            if (res.data.data[i].status==1){
              zhaopin.push(res.data.data[i])
              
            }
          }
          console.log("8888");
          console.log(zhaopin)
            that.setData({
              listData: zhaopin
            });
        }
    })
  },
  // d点击次数+1
  addtap(lunboId){
    console.log(lunboId)
    wx.request({
      url: serveUrl + "add_lunbo_counts",
      data: {
        lunbo_id: lunboId
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        console.log("次数加好了");
        console.log(res)
      }
    })
  },
  // 加载轮播图片
  lunboImg(){
    var that=this;
    wx.request({
      url: serveUrl + "get_lunbo_data",
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      data: {
        page: 1
      },
      success: function (res) {
        console.log("lunbo")
        console.log(res);
        var lunboArr=[];
        var lunboList = res.data.data;
        for(var i=0;i<lunboList.length;i++){
          var lunboObj = {};
          if (lunboList[i].status==1){
            console.log(lunboList[i]);
            lunboObj.photo = 'https://www.logclub.com/xahh/1/' + lunboList[i].image;
          lunboObj.lunboId = lunboList[i].lunbo_id;
          lunboObj.recruitId = lunboList[i].recruit_id.recruit_id;
          lunboObj.others = JSON.stringify(lunboList[i])
          lunboArr.push(lunboObj)
          }    
        }
        that.setData({
          lunboData: lunboArr
        });
      }
    })
  },
 
  //页面滑动到底部
  bindDownLoad: function () {
    var that = this;
    loadMore(that);
    console.log("lower");
  },
  scroll: function (event) {
    //该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },
  topLoad: function (event) {
    //  该方法绑定了页面滑动到顶部的事件，然后做上拉刷新
    page = 0;
    this.setData({
      list: [],
      scrollTop: 0
    });
    // loadMore(this);
    // console.log("lower");
  }
})
